package com.random.fox.whatspay.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.random.fox.whatspay.R;

/**
 * Created by 渠 on 2014/9/1.
 */
public class MainAty extends SlidingFragmentActivity {

    private String TAG = "MAIN";

    /**
     * 左侧菜单模块
     */
    private MenuFragment menuFragment;

    /**
     * 详细花费信息
     */
    private DetailFragment detailFragment;

    private FragmentManager fragmentManager;

    /**
     * 用户界面
     */
    private AccountFragment accountFragment;

    /**
     * 设置界面
     */
    private Settings settings;

    public static final int MENU = 1;

    public static final int ACCOUNT =1 ;
    public static final int DETAIL = 2;
    public static final int SETTING = 4;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        fragmentManager = getSupportFragmentManager();
        if (savedInstanceState == null) {
            FragmentTransaction t = fragmentManager.beginTransaction();
            menuFragment = new MenuFragment();
            t.replace(R.id.menu_frame, menuFragment);
            t.commit();
        } else {
            menuFragment = (MenuFragment) fragmentManager.findFragmentById(R.id.menu_frame);
        }

        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        setSlidingActionBarEnabled(false);

        accountFragment = new AccountFragment();
        detailFragment = new DetailFragment();
        settings = new Settings();

        fragmentManager.beginTransaction().add(R.id.main_frame, detailFragment).commit();

        setContentView(R.layout.main);
        setBehindContentView(R.layout.menu_frame);
    }


    public void showContent(int content,Intent intent){
        if (fragmentManager==null)
            fragmentManager = getSupportFragmentManager();

        FragmentTransaction ft = fragmentManager.beginTransaction();
        switch (content){
            case ACCOUNT:
                ft.replace(R.id.main_frame,accountFragment).commit();
                break;
            case DETAIL:
                ft.replace(R.id.main_frame,detailFragment).commit();
                break;
            case SETTING:
                ft.replace(R.id.main_frame,settings).commit();
                break;
        }
        showContent();
    }

}
